package com.eddy.liveline.user.controller;

import com.eddy.liveline.core.spring.mybatis.pagehelper.Table;
import com.eddy.liveline.core.utils.guid.Guid;
import com.eddy.liveline.user.pojo.Account;
import com.eddy.liveline.user.pojo.AccountTableQuery;
import com.eddy.liveline.user.service.AccountService;
import com.google.common.collect.Lists;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class AccountControl {

    private Logger logger = LogManager.getLogger(this.getClass());

    @Resource
    private AccountService accountService;

    @RequestMapping(value = {"/save"})
    @ResponseBody
    public Map save() {
        HashMap<String, Object> map = new HashMap<>();
        Account account = new Account();
        account.setId(Guid.generateId());
        account.setAccountName("eddy");
        boolean b = accountService.batchSave(Lists.newArrayList(account));
        if(b)
            map.put("code","successs");
            map.put("msg",account);
        return map;
    }


    @RequestMapping(value = {"/get/{id}"})
    @ResponseBody
    public Account get(@PathVariable("id") String id) {
        return accountService.getById(id);
    }

    @RequestMapping(value = {"/list"})
    @ResponseBody
    public Table<Account> convertPage(AccountTableQuery accountTableQuery) {
        Table<Account> query = accountService.query(accountTableQuery);
        return query;
    }

}
